import Vue from 'vue'
import Vuex from 'vuex'
import VuexPersistence from 'vuex-persist'

Vue.use(Vuex)

// Vuex持久化储存 vuex-persist 
const vuexLocal = new VuexPersistence({
  storage: window.localStorage,
  reducer: state => ({
    token: state.token,
    FormData: state.FormData,
    barColor: state.barColor,
    barImage: state.barImage,
    drawer: state.drawer
  })
})

export default new Vuex.Store({
  state: {
    barColor: 'rgba(0, 0, 0, .8), rgba(0, 0, 0, .8)',
    barImage: 'https://demos.creative-tim.com/material-dashboard/assets/img/sidebar-1.jpg',
    drawer: null,
    FormData: {
      ip: "47.99.158",
      port: "888",
      user: "",
      password: ""
    },
    token: ""
  },
  mutations: {
    SET_BAR_IMAGE(state, payload) {
      state.barImage = payload
    },
    SET_DRAWER(state, payload) {
      state.drawer = payload
    },
    FORM_DATA(state, payload) {
      state.FormData = payload
    },
    SET_TOKEN(state, token) {
      state.token = token
    }
  },
  actions: {},
  plugins: [vuexLocal.plugin]
})
